using MonorailTest.Core.DTO;
using MonorailTest.Core.Mapper;
using MonorailTest.Core.Repositories;

namespace MonorailTest.Core.Business
{
    public class PostBusiness : IPostBusiness
    {
        private readonly IPostMapper postMapper;
        private IPostRepository postRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="PostBusiness"/> class.
        /// </summary>
        /// <param name="postMapper">The post mapper.</param>
        /// <param name="postRepository">The post repository.</param>
        public PostBusiness(IPostMapper postMapper, IPostRepository postRepository)
        {
            this.postMapper = postMapper;
            this.postRepository = postRepository;
        }

        /// <summary>
        /// Saves the post.
        /// </summary>
        /// <param name="postDTO">The post DTO.</param>
        /// <returns></returns>
        public PostSavedDTO SavePost(NewPostDTO postDTO)
        {
            var post = postMapper.MapFrom(postDTO);
            postRepository.Save(post);
            return new PostSavedDTO(true);
        }
    }
}